package com.project.platform.utils;

import com.project.platform.dto.CurrentUserDTO;

public class CurrentUserThreadLocal {//实现多线程


     //线程变量隔离，ThreadLocal为每个线程提供了独立的变量副本，使得每个线程都能独立地改变自己的副本

    private static final ThreadLocal<CurrentUserDTO> currentUser = new ThreadLocal<>();

    //清除当前线程的用户信息
    public static void clear() {
        currentUser.remove();
    }

    //储存当前用户作为一个线程
    public static void set(CurrentUserDTO currentUserDTO) {
        currentUser.set(currentUserDTO);
    }

    //获取当前线程的用户信息，从当前线程的ThreadLocal变量中获取CurrentUserDTO对象
    //
    public static CurrentUserDTO getCurrentUser() {
        return currentUser.get();
    }


}
